<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>地图显示</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
    <style>
        html,
        body,
        #container {
            height: 100%;
            width: 100%;
        }
    </style>
</head>
<body>
<div id="container"></div>
<div>
    <input id="position"name="position"type="hidden">
</div>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=e27195e43f8628bcda450fcf8f5ec924"></script>
<script type="text/javascript">
    var map = new AMap.Map('container', {
        resizeEnable: true
    });
    // 使用clearMap方法删除所有覆盖物
    map.clearMap();

    //接受数据
    var position=data.position();
    S("#position").val(position);
</script>
<table>
    <tbody>
    <tr th:each="position: ${positions}"type="hidden">

    </tbody>
</table>
<script>
    var tb=document.getElementById("tableld");
    var rows=tb.rows;
    var markers=new Array();
    for(var i=0;i<rows.length;i++) {
        var cells=rows[i+1].cells;
        var lnglat=new Array();
        for(var j=0;j<cells.length;j++)
        {
            lnglat[j]=cells[j]
        }
        var marker= new AMap.Marker({
            position: new AMap.LngLat(lnglat[0],lnglat[1]),   // 经纬度对象，也可以是经纬度构成的一维数组
            title:''
        });
        map.add(marker);
        searchResultMap[i]=marker;
    }
    //绑定点击事件
    for(var i=0;i<rows.length;i++) {
        (function () {
            var p = i;
            searchResultMap[i].on('click', function () {
                //返回点击的经纬度
                var arry = new Array();
                arry[0] = searchResultMap[p].getPosition().getLng().toString();
                arry[1] = searchResultMap[p].getPosition().getLat().toString();
                url = "test.jsp?arry=" + arry;
            })
        })();
    }


</script>
</body>
</html>